package com.kaishengit.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.IdeaDao;
import com.kaishengit.pojo.Idea;
import com.kaishengit.pojo.Project;
import com.kaishengit.pojo.User;
import com.kaishengit.util.DateUtil;

@Service
@Transactional
public class IdeaService {
	private IdeaDao ideaDao;
	private Idea idea;

	public void save() {
		ideaDao.save(idea);
	}

	public void save(Idea idea, User user, Project project) {
		idea.setCreatetime(DateUtil.getDate());
		idea.setUser(user);
		idea.setProject(project);
		ideaDao.save(idea);
	}

	public void update() {
		ideaDao.update(idea);
	}

	public void update(Idea idea, User user, Project project) {
		idea.setCreatetime(DateUtil.getDate());
		idea.setUser(user);
		idea.setProject(project);
		ideaDao.saveOrUpdate(idea);

	}

	public void del(int id) {
		ideaDao.del(id);
	}

	public Idea findById(int id) {
		return ideaDao.findById(id);
	}

	public List<Idea> findAll() {
		return ideaDao.findAll();
	}

	@Autowired
	public void setIdeaDao(IdeaDao ideaDao) {
		this.ideaDao = ideaDao;
	}

	public Idea getIdea() {
		return idea;
	}

	public void setIdea(Idea idea) {
		this.idea = idea;
	}

	public List<Idea> findByProjectId(Project project) {
		return ideaDao.findByProjectId(project);
	}

}
